import xml.etree.ElementTree as ET


class NfoUtils:
    def __init__(self, xml_file_path):
        try:
            self.xml_file_path = xml_file_path
            self.tree = ET.parse(xml_file_path)
            self.root = self.tree.getroot()
        except Exception as err:
            print(str(err))

    def get_element_value(self, element_path):
        try:
            element = self.root.find(element_path)
            return element.text if element is not None else None
        except Exception as err:
            print(str(err))
        # finally:
        #    break

    def get_all_element_value(self, element_path):
        elements = ""
        for element in self.root.iter(element_path):
            elements += element.text + ","
        return elements[:-1] if len(elements) > 0 else elements

    def find_all_element_value(self, element_path):
        elements = ""
        for element in self.root.findall(element_path):
            elements += element.find("name").text + ","
        return elements[:-1] if len(elements) > 0 else elements
